//package com.kungfuhacking.wristbandpro.my.activity;
//
//import android.app.Dialog;
//import android.content.DialogInterface;
//import android.content.Intent;
//import android.os.Bundle;
//import android.support.v7.widget.DefaultItemAnimator;
//import android.support.v7.widget.GridLayoutManager;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.support.v7.widget.helper.ItemTouchHelper;
//import android.text.TextUtils;
//import android.view.View;
//import android.view.WindowManager;
//import android.widget.EditText;
//import android.widget.ImageView;
//import android.widget.TextView;
//
//import com.kungfuhacking.wristbandpro.R;
//import com.kungfuhacking.wristbandpro.base.view.BaseActivity;
//import com.kungfuhacking.wristbandpro.custom.TitleBarView;
//import com.kungfuhacking.wristbandpro.my.bean.Family;
//import com.kungfuhacking.wristbandpro.my.bean.FamilyData;
//import com.kungfuhacking.wristbandpro.my.presenter.FamilyNumAdapter;
//import com.kungfuhacking.wristbandpro.my.presenter.IFamilyNumsPresenter;
//import com.kungfuhacking.wristbandpro.my.view.IFamilyNumsView;
//import com.kungfuhacking.wristbandpro.utils.Constant;
//import com.kungfuhacking.wristbandpro.widget.ActionSheetDialog;
//import com.kungfuhacking.wristbandpro.widget.swipe.DividerItemDecoration;
//import com.kungfuhacking.wristbandpro.widget.swipe.OnItemClickListener;
//
//import java.util.ArrayList;
//
///**
// * 家庭信息详情
// * Created by Aaron on 17/6/2.
// */
//
//public class FamilyDetailsActivity extends BaseActivity implements View.OnClickListener, IFamilyNumsView {
//
//    private String childID;
//    private RecyclerView recycleView;
//    private IFamilyNumsPresenter iFamilyNumsPresenter = new IFamilyNumsPresenter(this);
//    private FamilyData familyData = new FamilyData();
//    private FamilyNumAdapter familyNumAdapter;
//    private int level;
//    private EditText et_address;
//    private Dialog cardAddressDialog;
//    private EditText et_card_address;
//    private ArrayList<Family> families = new ArrayList<>();
//    private String TAG = getClass().getSimpleName();
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//        setContentView(R.layout.activity_family_details);
//        initView();
//        childID = getIntent().getStringExtra("childId");
//        level = getIntent().getIntExtra("level", 0);
//    }
//
//    @Override
//    protected void onResume() {
//        super.onResume();
//        iFamilyNumsPresenter.familyInfo(childID);
//    }
//
//    private void initView() {
//        recycleView = (RecyclerView) findViewById(R.id.recycleView);
//        ImageView ivCounts = (ImageView) findViewById(R.id.ivCounts);
//        TitleBarView tbv = (TitleBarView) findViewById(R.id.tbv);
//
//        tbv.setOnLeftClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                finish();
//            }
//        });
//
//        ivCounts.setOnClickListener(this);
//        initRecycleView();
//    }
//
//    private void initRecycleView() {
//
//        recycleView.setLayoutManager(new LinearLayoutManager(this));
//        recycleView.setItemAnimator(new DefaultItemAnimator());
//        familyNumAdapter = new FamilyNumAdapter(this, familyData);
//        recycleView.setAdapter(familyNumAdapter);
//        recycleView.addItemDecoration(new DividerItemDecoration(this,
//                DividerItemDecoration.VERTICAL_LIST,
//                getResources().getDrawable(R.color.bg_gray)));
//
//        recycleView.addOnItemTouchListener(new OnItemClickListener(recycleView) {
//            @Override
//            public void onItemClick(RecyclerView.ViewHolder holder, int position) {
//
//            }
//
//            @Override
//            public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
//
//            }
//        });
//        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
//            @Override
//            public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
////dragFlags的时候，就会在长按item的时候进入拖动模式，然后就会一直回调onMove函数。我们可以在onMove中进行数据集的更新
//                final int dragFlags;//用于拖拽的标志 如果是网格布局，拖动方向为上下左右，否则只有上下方向
//                final int swipeFlags;//滑动标记
//                if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
//                    dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
//                    swipeFlags = 0;
//                } else {
//                    dragFlags = 0;
//                    swipeFlags = ItemTouchHelper.START;
//                }
//                return makeMovementFlags(dragFlags, swipeFlags);
//            }
//
//            @Override
//            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
//                return false;
//            }
//
//            @Override
//            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
//                int position = viewHolder.getAdapterPosition();
////                Log.d(TAG, "删除前的个数: " + familyData.getFamily().size() + ", 删除的position:" + position);
//                families = new ArrayList<>();
//                //删除家庭成员
//                families.addAll(familyData.getFamily());
////                Log.e(TAG, "删除前集合的个数:" + families.size());
////                Log.d(TAG, "本删除的position的name:" + families.get(position).getName());
//                families.remove(position);
//
//                iFamilyNumsPresenter.updateFamilyInfo("", "", "", "", families, childID);
//            }
//
//        });
//        itemTouchHelper.attachToRecyclerView(recycleView);
//    }
//
//    @Override
//    public void setBottomInfo(String address, String houseType, String hukouType, String hukouAddress, ArrayList<Family> families) {
//
//        if (!TextUtils.isEmpty(address))
//            familyData.setAddress(address);
//
//        if (!TextUtils.isEmpty(houseType))
//            familyData.setHouseType(houseType);
//
//        if (!TextUtils.isEmpty(hukouType))
//            familyData.setHukouType(hukouType);
//
//        if (!TextUtils.isEmpty(hukouAddress))
//            familyData.setHukouAddress(hukouAddress);
//
//        if (families != null)
//            familyData.setFamily(families);
//
////        for (int i = 0; i < familyData.getFamily().size(); i++) {
////            Log.e(TAG, "adapter 设置的 " + familyData.getFamily().get(i).getName());
////        }
//
//        familyNumAdapter.setFamilyData(familyData);
//        familyNumAdapter.notifyDataSetChanged();
//
//    }
//
//
//    @Override
//    public void onClick(View v) {
//
//        switch (v.getId()) {
//
//            case R.id.ivCounts://添加家庭成员
//                if (level == Constant.POWER_ADMIN) {
//                    //是管理员才可以添加家庭成员
//                    Intent mIntent = new Intent(this, AddFamilyNumActivity.class);
//                    mIntent.putExtra("childID", childID);
//                    mIntent.putParcelableArrayListExtra("families", familyData.getFamily());
//                    startActivity(mIntent);
//                } else
//                    showErr("无权限");
//
//                break;
//
//            case R.id.tv_card_cancle:
//                if (cardAddressDialog != null && cardAddressDialog.isShowing())
//                    cardAddressDialog.dismiss();
//                break;
//
//            case R.id.tv_cancle:
//                if (addressDialog != null && addressDialog.isShowing())
//                    addressDialog.dismiss();
//                break;
//
//            case R.id.tv_sure: //更改地址
//                if (addressDialog != null && addressDialog.isShowing())
//                    addressDialog.dismiss();
//                iFamilyNumsPresenter.updateFamilyInfo(et_address.getText().toString().trim(), "", "", "", null, childID);
//                break;
//
//            case R.id.tv_card_sure: //更改户口地址
//                if (cardAddressDialog != null && cardAddressDialog.isShowing())
//                    cardAddressDialog.dismiss();
//                iFamilyNumsPresenter.updateFamilyInfo("", "", "", et_card_address.getText().toString().trim(), null, childID
//                );
//
//        }
//
//    }
//
//    //房产情况
//    public void changeHouseConduction() {
//
//        if (level != Constant.POWER_ADMIN) {
//            showErr("无权限");
//            return;
//        }
//
//        new ActionSheetDialog(this)
//                .builder()
//                .setCancelable(true)
//                .setCanceledOnTouchOutside(true)
//                .addSheetItem("自有", ActionSheetDialog.SheetItemColor.Blue,
//                        new ActionSheetDialog.OnSheetItemClickListener() {
//                            @Override
//                            public void onClick(int which) {
////                                 自有
//                                iFamilyNumsPresenter.updateFamilyInfo("", "自有", "", "", null, childID);
//                            }
//
//                        })
//                .addSheetItem("租赁", ActionSheetDialog.SheetItemColor.Blue,
//                        new ActionSheetDialog.OnSheetItemClickListener() {
//                            @Override
//                            public void onClick(int which) {
////                                 租赁
//                                iFamilyNumsPresenter.updateFamilyInfo("", "租赁", "", "", null, childID);
//                            }
//                        }).show();
//
//    }
//
//    private Dialog addressDialog;
//
//    //地址
//    public void changeAddress() {
//
//        if (level != Constant.POWER_ADMIN) {
//            showErr("无权限");
//            return;
//        }
//
//        addressDialog = new Dialog(this, R.style.no_title);
//        addressDialog.setCancelable(true);
//        addressDialog.setCanceledOnTouchOutside(true);
//        addressDialog.show();
//        addressDialog.setContentView(R.layout.dialog_add_address);
//        changeScreen(0.5f);
//
//        addressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
//            @Override
//            public void onDismiss(DialogInterface dialogInterface) {
//                changeScreen(1.0f);
//            }
//        });
//
//        et_address = (EditText) addressDialog.findViewById(R.id.et_address);
//        TextView tv_cancle = (TextView) addressDialog.findViewById(R.id.tv_cancle);
//        TextView tv_sure = (TextView) addressDialog.findViewById(R.id.tv_sure);
//
//        tv_sure.setOnClickListener(this);
//        tv_cancle.setOnClickListener(this);
//
//    }
//
//    private void changeScreen(float f) {
//        WindowManager.LayoutParams lp = getWindow().getAttributes();
//        lp.alpha = f;
//        lp.dimAmount = f;
//        getWindow().setAttributes(lp);
//    }
//
//    //户口类型
//    public void changeIDStyle() {
//
//        if (level != Constant.POWER_ADMIN) {
//            showErr("无权限");
//            return;
//        }
//
//        new ActionSheetDialog(this)
//                .builder()
//                .setCancelable(true)
//                .setCanceledOnTouchOutside(true)
//                .addSheetItem("非农", ActionSheetDialog.SheetItemColor.Blue,
//                        new ActionSheetDialog.OnSheetItemClickListener() {
//                            @Override
//                            public void onClick(int which) {
////                                 非农
//                                iFamilyNumsPresenter.updateFamilyInfo("", "", "非农", "", null, childID);
//
//                            }
//
//                        })
//                .addSheetItem("农业", ActionSheetDialog.SheetItemColor.Blue,
//                        new ActionSheetDialog.OnSheetItemClickListener() {
//                            @Override
//                            public void onClick(int which) {
////                                 农业
//                                iFamilyNumsPresenter.updateFamilyInfo("", "", "农业", "", null, childID);
//
//                            }
//                        }).show();
//
//    }
//
//    //户口地址
//    public void changeIDAddress() {
//
//        if (level != Constant.POWER_ADMIN) {
//            showErr("无权限");
//            return;
//        }
//
//        cardAddressDialog = new Dialog(this, R.style.no_title);
//// new Dialog();
//        cardAddressDialog.setCancelable(true);
//        cardAddressDialog.setCanceledOnTouchOutside(true);
//        cardAddressDialog.show();
//        cardAddressDialog.setContentView(R.layout.dialog_add_card_address);
////        whiteListDialog.getWindow().setContentView(R.layout.dialog_add_white_list);
////        whiteListDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
//        changeScreen(0.5f);
//
//        cardAddressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
//            @Override
//            public void onDismiss(DialogInterface dialogInterface) {
//                changeScreen(1.0f);
//            }
//        });
//
//        et_card_address = (EditText) cardAddressDialog.findViewById(R.id.et_card_address);
//        TextView tv_card_cancle = (TextView) cardAddressDialog.findViewById(R.id.tv_card_cancle);
//        TextView tv_card_sure = (TextView) cardAddressDialog.findViewById(R.id.tv_card_sure);
//
//        tv_card_sure.setOnClickListener(this);
//        tv_card_cancle.setOnClickListener(this);
//    }
//
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        iFamilyNumsPresenter.clearRequest();
//    }
//
//    @Override
//    public void setAdapterData(FamilyData familyData) {
//        this.familyData = familyData;
//        familyNumAdapter.setFamilyData(familyData);
//        familyNumAdapter.notifyDataSetChanged();
//    }
//
//
//}
